﻿// $Id: Memento.cs 10 2008-02-29 15:58:02Z mcartoixa $
/*
 *  Copyright (C) 2007 NourY Solutions
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 3 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library. If not, see <http://www.gnu.org/licenses/>.
 *
 */
/*! \file
 * \brief Definition of \c Salamanca.DataActivities.Memento.
 *
 * \author $Author: mcartoixa $
 * \date $Date: 2008-02-29 16:58:02 +0100 (ven., 29 févr. 2008) $
 * \version $Revision: 10 $
 */

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;

namespace Salamanca.DataActivities
{



    ///////////////////////////////////////////////////////////////////////////
    ///
    /// <summary>Interface of a memento originator.</summary>
    ///
    ///////////////////////////////////////////////////////////////////////////

    internal interface IActivityStateMementoOriginator
    {

        /// <summary>Creates a new memento.</summary>
        /// <returns>A new memento.</returns>
        IActivityStateMemento CreateMemento();
    }



    ///////////////////////////////////////////////////////////////////////////
    ///
    /// <summary>Interface of a process state <a href="http://www.dofactory.com/Patterns/PatternMemento.aspx">Memento</a>.</summary>
    ///
    ///////////////////////////////////////////////////////////////////////////

    internal interface IActivityStateMemento
    {

        /// <summary>Gets the process state stored by this memento.</summary>
        IActivityState State
        {
            get;
        }

        /// <summary>Gets the process data stored by this memento.</summary>
        object DataBackup
        {
            get;
        }
    }



    ///////////////////////////////////////////////////////////////////////////
    ///
    /// <summary>Implementation of a process state <a href="http://www.dofactory.com/Patterns/PatternMemento.aspx">Memento</a>.</summary>
    ///
    ///////////////////////////////////////////////////////////////////////////

    internal class ActivityStateMemento:
        IActivityStateMemento
    {

        /// <summary>Creates a new memento for the spcified state.</summary>
        /// <param name="state">The state against which the memento is created.</param>
        public ActivityStateMemento(IActivityState state)
        {
            _State=state;
            _DataBackup=((IBackupable)state.Data).CreateBackup();
        }

        /// <summary>Gets the process state stored by this memento.</summary>
        public IActivityState State
        {
            get
            {
                return _State;
            }
        }

        /// <summary>Gets the process data stored by this memento.</summary>
        public object DataBackup
        {
            get
            {
                return _DataBackup;
            }
        }

        /// <summary>The process state stored by this memento.</summary>
        private IActivityState _State;
        /// <summary>The process data stored by this memento</summary>
        private object _DataBackup;
    }
}
